-- ================================== Modified by Tronex ================================= -- Ported from Call of Chernobyl 1.5 -- Last modification: 2017/12/16 -- ======================================================================================= -- You can create your custom scripted keybinds -- PDA keybinds are at the bottom -- Handler for scripted keybinds local binded_actions = {} -- To add new keybinds, simply call axr_keybind.bind(dik_or_bind,functor). Param passed is 1 if pressed or 0 if released and 2 if held. -- In engine there has been 15 custom dik binds made for script use (ie. kCUSTOM1 to kCUSTOM15) see ui_keybinding.xml. -- Otherwise use DIK_keys. If you want them rebindable through axr_options.ltx, then specify an alias as the 3rd param. ------------------------------------------------------------------ -- Bind keypress to function ------------------------------------------------------------------ function bind(dik_or_bind,functor,alias) if not (binded_actions[dik_or_bind]) then binded_actions[dik_or_bind] = {} end binded_actions[dik_or_bind][functor] = alias or dik_or_bind end function unbind(dik_or_bind,functor) if (binded_actions[dik_or_bind]) then binded_actions[dik_or_bind][functor] = nil end end -------------------------------------------------------------------- -- On Game Start -------------------------------------------------------------------- function on_game_start() RegisterScriptCallback("on_key_press",on_key_press) RegisterScriptCallback("on_key_release",on_key_release) RegisterScriptCallback("on_key_hold",on_key_hold) local need_save for dik_or_bind,t in pairs(binded_actions) do for functor,alias in pairs(t) do if (key_bindings[dik_or_bind] == nil and alias ~= dik_to_bind) then if not (axr_main.config:line_exist("global_keybinds",alias)) then axr_main.config:w_value("global_keybinds",alias,dik_or_bind) need_save = true end end end end if (need_save) then axr_main.config:save() end end ------------------------------------------- -- callbacks ------------------------------------------- function on_key_release(key) try_key_action(key,0) end function on_key_press(key) try_key_action(key,1) end function on_key_hold(key) try_key_action(key,2) end function try_key_action(key,typ) for dik_or_bind,t in pairs(binded_actions) do for functor,alias in pairs(t) do if (key_bindings[dik_or_bind]) then if (key_bindings[dik_or_bind] == dik_to_bind(key)) then functor(typ) end elseif (key == DIK_keys[axr_main.config:r_value("global_keybinds",alias,0,"")]) then functor(typ) end end end end